package wicket;

import java.util.List;
import java.util.Vector;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;

public class MessageForm extends Form {

	private static final long serialVersionUID = 1L;
	private Message message = new Message();
	private List<Message> listMessage = new Vector<Message>();
	
	public MessageForm(String id) {
		super(id);
		PropertyModel nameProperty = new PropertyModel(getMessage(), "message");
		TextField messageTextField = new TextField("message", nameProperty);
		this.add(messageTextField);
	}
	
	@Override
	protected void onSubmit(){
		Message newMessage = new Message();
		newMessage.setMessage(message.getMessage());

		getListMessage().add(0, newMessage);
		((ListPanel)getParent()).getMessageListView().modelChanged();

		message.setMessage("");
	}
	
	public void setMessage(Message message) {
		this.message = message;
	}

	public Message getMessage() {
		return message;
	}

	public void setListMessage(List<Message> listMessage) {
		this.listMessage = listMessage;
	}

	public List<Message> getListMessage() {
		return listMessage;
	}


}
